<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Index</title>

    <style>
        .container {
            position: relative;

            height: 300px;
            width: 300px;
            background-color: bisque;
            margin: 100px auto;
        }

        .box {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);

            /* 文字居中 */
            height: 100px;
            text-align: center;
            line-height: 100px;
            width: 100px;
            background-color: cornsilk;
        }
    </style>
</head>

<body>

    <div class="container">
        <div class="box">center</div>
    </div>

</body>

</html>